import { spawn } from 'child_process';

export async function exec(
  script: string,
  params: string[] = [],
  command: string = 'python3',
): Promise<string> {
  return new Promise((r, e) => {
    const std = spawn(command, [script, ...params]);
    std.stdout.on('data', (data) => r(data.toString()));
    std.stderr.on('data', (data) => {
      console.error(data.toString());
      e(data.toString());
    });
  });
}
